package com.ruoyi.web.controller.system;

import cn.hutool.core.date.DateUtil;
import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.TInspection;
import com.ruoyi.system.service.ITInspectionService;
import com.ruoyi.common.utils.poi.ExcelUtil;

/**
 * 巡视巡查评价Controller
 * 
 * @author ruoyi
 * @date 2024-02-28
 */
@RestController
@RequestMapping("/system/inspection")
public class TInspectionController extends BaseController
{
    @Autowired
    private ITInspectionService tInspectionService;

    /**
     * 查询巡视巡查评价列表
     */
    @PreAuthorize("@ss.hasPermi('system:inspection:list')")
    @GetMapping("/list")
    public AjaxResult list(TInspection tInspection)
    {
        List<TInspection> list = tInspectionService.selectTInspectionList(tInspection);
        return success(list);
    }

    /**
     * 导出巡视巡查评价列表
     */
    @PreAuthorize("@ss.hasPermi('system:inspection:export')")
    @Log(title = "巡视巡查评价", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TInspection tInspection)
    {
        List<TInspection> list = tInspectionService.selectTInspectionList(tInspection);
        ExcelUtil<TInspection> util = new ExcelUtil<TInspection>(TInspection.class);
        util.exportExcel(response, list, "巡视巡查评价数据");
    }

    /**
     * 获取巡视巡查评价详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:inspection:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(tInspectionService.selectTInspectionById(id));
    }

    /**
     * 新增巡视巡查评价
     */
    @PreAuthorize("@ss.hasPermi('system:inspection:add')")
    @Log(title = "巡视巡查评价", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TInspection tInspection)
    {
        return toAjax(tInspectionService.insertTInspection(tInspection));
    }

    /**
     * 修改巡视巡查评价
     */
    @PreAuthorize("@ss.hasPermi('system:inspection:edit')")
    @Log(title = "巡视巡查评价", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TInspection tInspection)
    {
        return toAjax(tInspectionService.updateTInspection(tInspection));
    }

    /**
     * 删除巡视巡查评价
     */
    @PreAuthorize("@ss.hasPermi('system:inspection:remove')")
    @Log(title = "巡视巡查评价", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(tInspectionService.deleteTInspectionByIds(ids));
    }


    /**
     * 巡视巡查评价亮灯
     */
    @PreAuthorize("@ss.hasPermi('system:inspection:add')")
    @Log(title = "巡视巡查评价亮灯", businessType = BusinessType.UPDATE)
    @RequestMapping(value = "/inspectionEvaluation",method = RequestMethod.POST)
    public AjaxResult inspectionEvaluation(@RequestBody TInspection tInspection)
    {

        tInspection.setEvaluationDate(DateUtil.date());
        return toAjax(tInspectionService.updateTInspection(tInspection));
    }
}
